package cn.bdqn.consumer1.controller;

import cn.bdqn.consumer1.feign.HelloFeign;
import cn.bdqn.consumer1.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class HelloController {

    @Autowired
    private HelloFeign helloFeign;

    @GetMapping("/hello")
    public String hello(@RequestParam("uname") String uname, @RequestParam("age") Integer age){
        return  helloFeign.hello(uname,age);
    }


    @PostMapping("/doLogin")
    public String doLogin(@RequestBody UserInfo userInfo){
        UserInfo userInfoLogin = helloFeign.doLogin(userInfo);
        if(userInfoLogin!=null){
           return "登录成功,欢迎你"+userInfoLogin.getUname()+",你的ID号是:"+userInfoLogin.getUid();
        }else{
            return "用户名或密码不对,登录失败";
        }
    }
    @PutMapping("updateUser")
    public String updateUser(@RequestBody UserInfo userInfo){
        System.out.println("consumer 获得的对象:"+userInfo.toString());
        int ret =  helloFeign.updateUser(userInfo);
        if(ret>0){
            return "修改成功,欢迎你";
        }else{
            return "修改失败";
        }
    }
    @GetMapping("/doLogin2")
    public String doLogin2(@RequestParam("uname") String uname, @RequestParam("upwd") String upwd){
        Map map = new HashMap<>();
        map.put("uname",uname);
        map.put("upwd",upwd);
        if(helloFeign.doLogin2(map)){
            return "登录成功,欢迎你";
        }else{
            return "用户名或密码不对,登录失败";
        }
    }
}
